import { fileURLToPath, URL } from 'node:url'

import {defineConfig, loadEnv} from 'vite'
import vue from '@vitejs/plugin-vue'
import {resolve} from 'path'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import {ElementPlusResolver} from 'unplugin-vue-components/resolvers'

// https://vitejs.dev/config/
const pathResolve = (dir) => {
  return resolve(__dirname, '.', dir);
};

const alias = {
  '@': pathResolve('./src/'),
};
export default defineConfig((mode) => {
  const env = loadEnv(mode.mode, process.cwd());
  return {
    plugins: [
      vue(),
      AutoImport({
        resolvers: [ElementPlusResolver()],
        imports: ['vue', 'vue-router']
      }),
      Components({
        resolvers: [ElementPlusResolver()]
      })
    ],
    root: process.cwd(),
    resolve: {alias},
    // optimizeDeps: {
    //   exclude: ['vue-demi'],
    // },
    server: {
      host: '0.0.0.0',
      port: 9527,
      hmr: true,
    }
  }
})
